﻿using System;

namespace Calendar1
{
    class Program
    {
        private static int getweek(int month, int day)//判断一个日期是星期几
        {
            DateTime dt = new DateTime(2022, month, day);
            return (int)dt.DayOfWeek;
        }
        private static int getdayofmonth(int month) //判断这个月有几天
        {
            switch (month)
            {
                case 2:
                    return 28;
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    return 31;
                default:
                    return 30;
            }
        }
        private static void printmonth(int month)//打印月历
        {
            int x = (month - 1) % 3 * 60;
            int y = (month - 1) / 3 * 15;
            Console.SetCursorPosition(x, y);
            Console.Write("{0}月", month);
            Console.SetCursorPosition(x, ++y);
            Console.WriteLine("日\t一\t二\t三\t四\t五\t六");
            int weeknum = getweek(month, 1);
            Console.SetCursorPosition(x, ++y);
            for (int i = 0; i < weeknum; i++)
                Console.Write("\t");
            int daynum = getdayofmonth(month);
            for (int i = 1; i < daynum + 1; i++)
            {
                Console.Write(i + "\t");
                if (getweek(month, i) == 6)//日期到了周六就换行输出
                    Console.SetCursorPosition(x, ++y);
            }
        }
        static void Main()
        {
            int bufferWidth = 180, bufferHeight = 60;//设置缓冲区大小
            int WindowWidth = 180, WindowHeight = 60;//设置窗口大小
            Console.SetBufferSize(bufferWidth, bufferHeight);
            Console.SetWindowSize(WindowWidth, WindowHeight);
            int count = 12;
            for (int i = 1; i <= count; i++)
                printmonth(i);
        }
    }
}